<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2018/8/22
 * Time: 下午8:07
 */

namespace api\models;


use common\models\Like;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\web\Link;
use yii\web\Linkable;

class Photo extends \common\models\Photo implements Linkable
{

    public function fields()
    {
        return [
            'id',
            'uid',
            'author_name' => function ($model) {
                return $model->user->username;
            },
            'avatar'      => function ($model) {
                return $model->user->avatarUrl;
            },
            'brife',
            'imgUrl'      => function ($model) {
                return $model->imgUrl;
            },
            'like'        => function ($model) {
                return Like::find()
                           ->where(['pid' => $model->id])
                           ->count();
            },
            'isLiked'     => function ($model) {
                return $model->isLiked;
            },
            'isCollected' => function ($model) {
                return $model->isCollected;
            },
            'comments'=>function($model){
                return $model->comments;
            },
            'iso',
//			'type',
            'make',
            'lens',
            'model',
            'exposer',
            'fnumber',
            'flength',
            'updated_at',
        ];
    }

    public function getComments(){
        return PhotoComment::findAll(['pid'=>$this->id]);
    }


    public function getLinks()
    {
        return [
            Link::REL_SELF => Url::to(['photo/view', 'id' => $this->id]),
//			'view'=>Url::to(['photo/view','id'=>$this->id]),
//			'like'=>Url::to([''])
//			 'userShow'=>Url::to(['user/show','id'=>$this->uid]),//用户信息请求地址

        ];
    }


}